#!/bin/bash
echo '#!/bin/bash
echo "正在检查系统是否更新..."
if [ $? -eq 0 ]; then
    echo "系统已更新"
else
    apt update && apt upgrade -y
    echo "开始更新"
fi

if ! [ -x "$(command -v lsb_release)" ]; then
    apt-get install lsb-release -y
fi

if [ "$(lsb_release -si)" != "Ubuntu" ]; then
    echo "该脚本仅适用于Ubuntu系统，请先打开Ubuntu或者摆烂"
    exit 1
fi

if [ "$(whoami)" != "root" ]; then
    sudo -i
fi

echo "您已经通过Ubuntu系统和root权限的检查，可以运行其他命令了"

if [ -d "$HOME/Miao-Yunzai" ]; then
    lsy="$HOME/Miao-Yunzai"
elif [ -d "$HOME/Yunzai-Bot" ]; then
    lsy="$HOME/Yunzai-Bot"
elif [ -d "$HOME/yxybot" ]; then
    lsy="$HOME/yxybot"
else
    echo "您未安装机器人,记得通过脚本安装机器人哦"
fi

if [ ! -d "$lsy/node_modules/icqq" ] && [ -d "$HOME/Yunzai-Bot" ]; then
    echo "没有icqq依赖"
    cd $lsy
    git remote set-url origin https://gitee.com/yoimiya-kokomi/Yunzai-Bot && git checkout . && git pull
    rm -rf $HOME/.pm2 $lsy/node_modules
    cd $lsy && pnpm i
    echo "换源成功"
fi

if [ -d "$HOME/Miao-Yunzai" ] && [ -d "$jh/qianyu-plugin" ]; then
    rm -rf $lsy/plugins/qianyu-plugin
fi

current_time=$(date "+%Y-%m-%d %H:%M:%S")
echo -e "\e[1;36m现在的时间是 : $current_time\e[0m"
function show_menu
{
echo -e "\e[1;32m╭────────────────────────────────────────────╮\e[0m"
echo -e "\e[1;32m│               向日葵安装脚本               │\e[0m"
echo -e "\e[1;32m│  https://gitee.com/xrk114514/shell-Yunzai  │\e[0m"
echo -e "\e[1;32m├─────────────────────┬──────────────────────┤\e[0m"
echo -e "\e[1;36m│    工作室674752705  │    答疑群279071460   │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  1 安装云崽         │ 2 安装插件(含ffmpeg) │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  3 安装js插件       │ 4 重启指令失效的问题 │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  5 浏览器修复       │ 6 登录错误           │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  7 写入云崽启动命令 │ 8 退出               │\e[0m"
echo -e "\e[1;32m├─────────────────────┼──────────────────────┤\e[0m"
echo -e "\e[1;36m│  9 向日葵密钥菜单   │ 10 向日葵贱贱动画    │\e[0m"
echo -e "\e[1;32m╰─────────────────────┴──────────────────────╯\e[0m"
}
echo -e "\e[1;32m向日葵祝您生活美好，事事顺利\e[0m"
cat <<xrk
╭───────────────────────────────────────────────────────────────────────╮
│   当前脚本版本为v2.0.1，脚本已写入本地，最大限度的提供运算速度与便利
│   ○○○●●● 如果要更新请输入r
╰───────────────────────────────────────────────────────────────────────╯
xrk
while [ 1 ]
do
    show_menu
    read -p "请从四个选项中选一个: " CHOICE

    case "$CHOICE" in
        1 )
            echo "向日葵qq1814632762"
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-yz/yz.sh)
            exit 1
            ;;
        2 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-all/plu.sh)
            ;;
        3 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-all/js.sh)
            ;;
        4 )
            if [ -d "$lsy" ]; then
            echo "正在修复重启命令失败问题"
            rm -rf $HOME/.pm2 $lsy/node_modules
            cd $lsy && pnpm i
            echo "成功，请输入yz打开云崽吧！"
               else
                   echo "请先安装云崽啊喂"
            fi
            ;;
        5 )
            echo "此方法如今不知道能不能用"
            apt-get install ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils -y
            exit 1
            ;;
        6 ) 
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-version-issue/bbgd.sh)
            ;;
        7 )
            bash <(curl -sL gitee.com/xrk114514/shell-Yunzai/raw/master/shell-yz/yzxz.sh)
            ;;
        8 ) 
            exit 1
            ;;
        9 ) 

            read -p "向日葵密钥: " value
            if [ "$value" = "小月亮" ] || [ "$value" = "向日葵真帅" ] || [ "$value" = "向日葵姐姐" ] || [ "$value" = "若雨" ] || [ "$value" = "平安" ]; then
                echo "密钥验证成功"
                else
                    echo "密钥验证失败"
                    exit 0
            fi
            dirname="xrk_token"
            if [ $(cat "/$dirname/$dirname") == "xrkwiudhebdi7wusydgbeis7xyeg3hiw7xyehejud7dgebjeudydgejidux" ] && [ -f "/$dirname/$dirname" ]; then
                echo "还在开发中哦"
                else
                    echo "密钥不存在或已经失效不存在"
            fi
            ;;
        10 )
            x=10
            y=5
            dx=1
            dy=0
            bean="."
            man="😅"
            wall="6"
            map=(
            "6666666666666666666666"
            "6欢迎来到向日葵的脚本6"
            "6....................6"
            "6....................6"
            "6....................6"
            "6...................6"
            "6....................6"
            "6....................6"
            "6....................6"
            "6....................6"
            "6....................6"
            "6666666666666666666666"
            )
                for ((i=0; i<30; i++))
                    do
                        clear
                        map[$y]=${map[$y]:0:$x}$man${map[$y]:$(($x+1))}
                        for ((j=0; j<12; j++))
                            do
                                echo ${map[$j]}
                                done
                                sleep 0.1
                                map[$y]=${map[$y]:0:$x}$bean${map[$y]:$(($x+1))}
                                if [[ ${map[$(($y+$dy))]:$x:1} == $wall || ${map[$(($y+$dy))]:$((x+1)):1} == $wall || ${map[$(($y+$dy))]:$((x-1)):1} == $wall ]]; then
                                    dy=$((-$dy))
                                    dx=$((-$dx))
                                        elif [[ ${map[$(($y+$dy))]:$x:1} == $man || ${map[$(($y+$dy))]:$((x+1)):1} == $man || ${map[$(($y+$dy))]:$((x-1)):1} == $man ]]; then
                                            dy=$((-$dy))
                                            x=$((-$dx))
                                fi
                                if [[ ${map[$y]:$(($x+$dx)):1} == $wall || ${map[$y]:$((x+$dx+1)):1} == $wall || ${map[$y]:$((x+$dx-1)):1} == $wall ]]; then
                                    dx=$((-$dx))
                                    dy=$((-$dy))
                                        elif [[ ${map[$y]:$(($x+$dx)):1} == $man || ${map[$y]:$((x+$dx+1)):1} == $man || ${map[$y]:$((x+$dx-1)):1} == $man ]]; then
                                            dx=$((-$dx))
                                            dy=$((-$dy))
                                fi
                                x=$(($x+$dx))
                                y=$(($y+$dy))
                   done
            ;;
         r )
            cd /usr/local/bin/
            echo "$(curl -sL https://gitee.com/xrk114514/shell-Yunzai/raw/master/xrk)" > xrk
            chmod 777 xrk
            cd ~
            ;;
         * )
             echo "让你乱点，给你退了"
             exit 1
            ;;
    esac
done
' | tee /usr/local/bin/xrk > /dev/null
chmod +x /usr/local/bin/xrk
cd /usr/local/bin/
echo "$(curl -sL https://gitee.com/xrk114514/shell-Yunzai/raw/master/xrk)" > xrk
chmod 777 xrk
cd ~